import * as user from './action-type'
import { is, fromJS } from 'immutable';  // 保证数据的不可变

let defaultState = {
  addressList: [],   // 地址列表
  addressName: '',  // 选中的地址
  temMessage: '', //临时姓名
  hasAddressList: [], // 已有的地址
  operate: 'edit',
  userInfo: {},
  geohash: [],
  hasAlert:false
}

// 用户消息
export default (state = defaultState, action = {}) => {
  switch (action.type) {
    case user.SAVE_USERINFO:    
    if (!is(fromJS(state.userInfo), fromJS(action.userInfo))) {
      return {
        ...state,
        userInfo: action.userInfo
      }
    }else{
      return state
    }
    case user.SAVE_ATTRINFO:
      return {...state, ...{[action.datatype]: action.value}};
    case user.MODIFY_USERINFO:
      return {...state, userInfo: {...state.userInfo, [action.key]: action.value}};
    case user.COMMON_HASALERT:
      console.log({...state, hasAlert:action.hasAlert})
      return {...state, hasAlert:action.hasAlert};
    default:
      return state
  }
}